package gui.pannelPartie;

import java.awt.Frame;


import gui.BeginDialogue.ChargementException;
import gui.pannelPartie.MatchList.EndManche;
import gui.pannelPartie.MatchList.PanelMatchList;
import gui.pannelPartie.TableauClassement.PanelClassement;
import html.HtmlBody;


import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import core.Concourt;

public class PanelPartie extends JTabbedPane implements EndManche ,HtmlBody{

	private static final long serialVersionUID = -6694435213536275753L;
	private Concourt concourt;
	private PanelClassement pc;
	private PanelMatchList pml;
	
	public PanelPartie(Concourt c,Frame owner){
		concourt=c;
		pc=new PanelClassement(concourt.getClassement());
		addMenu("Classement",pc);
		pml=new PanelMatchList(concourt.getMatchs(),owner,this);
		addMenu("Matchs",pml);
	}
	
	public PanelPartie(Concourt c,Frame owner, String charge,int inNbPoints) throws ChargementException {
		concourt=c;
		pc=new PanelClassement(concourt.getClassement());
		addMenu("Classement",pc);
		pml=new PanelMatchList(charge,owner,this,concourt.getClassement(),inNbPoints);
		addMenu("Matchs",pml);
	}

	private void addMenu(String name ,JPanel j){
		JPanel aux =new JPanel();
		aux.add(j);
		addTab(name,new JScrollPane(aux));
	}


	public void endManche() {
		pc.miseAJour(concourt.getClassement());
		if(concourt.haveSteelMatch())
			pml.refresh(concourt.getMatchs());
	}


	public String getHtmlBody() {
		StringBuffer res = new StringBuffer();
		res.append("<p>\n");
		res.append("<h1>Classement</h1>\n");
		res.append(pc.getHtmlBody());
		res.append("</p>\n");
		res.append("<p>\n");
		res.append("<h1>Matchs</h1>\n");
		res.append(pml.getHtmlBody());
		res.append("</p>\n");
		return res.toString();
	}

	public void refreshClassement() {
		pc.miseAJour(concourt.getClassement());		
	}

	public String save() {		
		return pml.save();
	}
	
}
